Gestionnaire de liens
Ce script permet de récupérer tous les liens que vous copiez, et se charge de trier en fonction des tags (que vous aurez défini au préalable). Il vous restituera tout ça dans un fichier texte. Le script n'est pas complet, il manque le mode manuel/ semi-automatique, ainsi que la gestion des tags etc... v1.1 Version beaucoup moins lourde, et plus simple. # -*- coding:Utf-8 -*- import 'win32clipboard, time, signal, sys '''def '''signal_handler(signal, frame): if len(newLink): read() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) '''def '''isLink(data): '''if '("http" '''or "www") in data: return True else: return False def '''write(linkSorted): file = open('C:/Users/Nico/Desktop/0Python/paste/liens.txt', 'w') '''for '''link '''in '''linkSorted: file.write(link+'\n') file.close() '''def '''read(): # récupère tag et lien s'il y en a '''try: file = open('C:/Users/Nico/Desktop/0Python/paste/liens.txt', 'r') success = file.readlines() file.close() except: success = False newTag = raw_input("Ajouter tags ? : ") if 'newTag: tag.append(newTag) '''if '''success: dataFile = success '''for '''element '''in '''dataFile: element = element.replace('\n', '') '''if '''isLink(element): # lien newLink.append(element) '''else: # sinon tag tag.append(element) sortLink() def '''sortLink(): linkSorted = [] tags = list(set(tag)) '''for '''categorie in tags: linkSorted.append(categorie) '''for '''link '''in '''newLink: '''if '''categorie '''in '''link.lower(): linkSorted.append(newLink.pop(newLink.index(link))) '''if len(newLink): if not '"Divers" '''in '''tags: linkSorted.append("Divers") '''for '''link '''in '''newLink write(linkSorted) '''def '''defineTag(): choix = None '''while '''choix != '': choix = raw_input('Definir de nouveaux tags : ') '''if '''choix: tag.append(choix) '''print '''tag newLink, tag = [], [] '''while '''1: '''try: win32clipboard.OpenClipboard() data=win32clipboard.GetClipboardData() win32clipboard.EmptyClipboard() contenuValide = True except: print ''''en attente...' contenuValide = False '''finally: win32clipboard.CloseClipboard() if 'contenuValide '''and '''isLink(data): newLink.append(data.replace('\n', '')) '''print '''data time.sleep(1.0) v1.0 # -*- coding:Utf-8 -*- '''import '''win32clipboard '''import '''time '''import '''signal '''import '''sys '''def '''signal_handler(signal, frame): trier() sys.exit(0) '''def '''ecrire(tabTrier, mode, isLog = False): path = 'C:/Users/Desktop/0Python/liens.txt' '''if '''isLog: path = 'C:/Users/Desktop/0Python/liens.log' file = open(path, mode) '''for '''tableau '''in '''tabTrier: '''if '''mode 'a+' and not isLog: '''for '''element in tableau: file.write(element+"\n") '''else: file.write(tableau+"\n") file.close() def '''lire(): isOpen = True '''try: fichier = open('C:/Users/Desktop/0Python/liens.txt', 'r+') except: isOpen = False i = 0 if 'isOpen: buffer = fichier.readlines() buffer.reverse() temp = [] '''for '''data in buffer: data = data.replace('\n', '') 'if ''http' in data: temp.append(data) '''else: temp.reverse() temp.insert(0, data) oldLink.append(temp) temp = [] fichier.close() return '''isOpen '''def '''trier(): #fichier log ecrire(newLink, 'a+', True) choix = raw_input('Choix mode auto ou manuel(1) : ') '''if not choix: print ' Mode Auto ' tabTrier = [] for '''tag in tags: temp = [] temp.append(tag) for link in newLink: # and not '.'+tag in link: if tag in link.lower(): print tag, 'associe a ', link temp.append(link) newLink.remove(link) '''if '''len(temp) > 1: tabTrier.append(temp) '''if '''len(newLink): newLink.insert(0, tags0) tabTrier.append(newLink) '''if not lire(): print 'test ok' ecrire(tabTrier, 'a+') else: taille = len(tabTrier) nbLien = 0 temp = [] tabTrier = tabTrier + oldLink tabTrier.sort() for 'element in tabTrier: '''for '''lien in element: '''if '''lien not in temp: temp.append(lien) '''if ''http' 'in '''lien '''or ''www' '''in '''lien: nbLien +=1 ecrire(temp, 'w') print nbLien, 'collectes !' signal.signal(signal.SIGINT, signal_handler) contenuValide = False tags = 'css', 'html', 'php', 'cpp', 'sql', 'python' newLink = [] global oldLink oldLink = [] intervalle = 5 '''while '''1: '''try: win32clipboard.OpenClipboard() data=win32clipboard.GetClipboardData() win32clipboard.EmptyClipboard() contenuValide = True except: print 'en attente...' contenuValide = False finally: win32clipboard.CloseClipboard() if 'contenuValide '''and '('http' in data or 'www' in data): print data newLink.append(data) intervalle = 0.5 '''else: intervalle = 1.5 time.sleep(intervalle)